package net.minecraft.src;

public class EnchantmentHandler {

	
	public static void doEnchantmentOnBlock(int x, int y, int z, World world, EntityPlayer ep, String enchantment) {
		ep.addChatMessage("Using enchantment on block.");
		InscriptionManager.checkInscription(x, y, z, world, ep);
		
		if(enchantment.equalsIgnoreCase("fireball")){
			if(world.getBlockId(x, y + 1, z) == 0 && Block.fire.canPlaceBlockAt(world, x, y, z)){
				world.setBlockWithNotify(x, y + 1, z, Block.fire.blockID);
			}
		}
		else if(enchantment.equalsIgnoreCase("lightning")){
			if(world.getBlockId(x, y + 1, z) == 0 && mod_Inscription.invisRedTorch.canPlaceBlockAt(world, x, y, z)){
				world.setBlockWithNotify(x, y + 1, z, mod_Inscription.invisRedTorch.blockID);
			}
		}
	}
	
	public static void doEnchantmentCast(World world, EntityPlayer ep, String enchantment) {
		ep.addChatMessage("Casting enchantment.");
		MovingObjectPosition mop = ep.rayTrace(1024D, 1F);

		
		if (enchantment.equalsIgnoreCase("fireball") && mop != null) {
			ep.addChatMessage("Casting fireball.");
            double d5 = mop.hitVec.xCoord - ep.posX;
            double d6 = mop.hitVec.yCoord - ep.posY+ep.height/2;
            double d7 = mop.hitVec.zCoord - ep.posZ;
			EntityFireball entityfireball = new EntityFireball(world, ep, d5,d6,d7);
            Vec3D vec3d = ep.getLook(1.0F);
            entityfireball.posX = ep.posX;
            entityfireball.posY = ep.posY;
            entityfireball.posZ = ep.posZ;
            world.entityJoinedWorld(entityfireball);
		}
		else if (enchantment.equalsIgnoreCase("lightning") && mop != null) {
			ep.addChatMessage("Casting lightning.");
			double d5 = mop.hitVec.xCoord - ep.posX;
            double d6 = mop.hitVec.yCoord - ep.posY+ep.height/2;
            double d7 = mop.hitVec.zCoord - ep.posZ;
            EntityLightningBolt entitylightning = new EntityLightningBolt(world, d5, d6, d7);
            Vec3D vec3d = ep.getLook(1.0F);
            entitylightning.posX += ep.posX + vec3d.xCoord;
            entitylightning.posZ += ep.posZ + vec3d.zCoord;
            //checks what yCoord the lightning should strike
            int yCheck = 1;
            while(!world.canBlockSeeTheSky((int)entitylightning.posX, yCheck, (int)entitylightning.posZ)) yCheck++;
            ep.addChatMessage("Block can see sky : yCheck[" + yCheck + "]");
            entitylightning.posY = yCheck;
            world.entityJoinedWorld(entitylightning);
		}
		else if (mop == null){
			ep.addChatMessage("Cannot cast spell.");
		}
	}
	
	public static void doEnchantmentOnEntity(World world, EntityPlayer ep, Entity target, String enchantment) {
		ep.addChatMessage("Using enchantment on entity.");
		
		if (!(target instanceof EntityLiving)) {
			return;
		}
	}
}
